// router/index.js
import { createRouter, createWebHistory } from "vue-router";

// 定义路由关系（使用懒加载）
const routes = [
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/Login.vue"),
  },
  {
    path: "/",
    component: () => import("@/views/Layout.vue"),
    redirect: "/dashboard",
    children: [
      { path: "/dashboard", name: "Dashboard", component: () => import("@/views/Dashboard.vue") },
      { path: "/cate", name: "Cate", component: () => import("@/views/Cate.vue") },
      { path: "/review", name: "Review", component: () => import("@/views/Review.vue") },
      { path: "/book", name: "Book", component: () => import("@/views/Book.vue") },
      { path: "/note", name: "Note", component: () => import("@/views/Note.vue") },
      {
        path: "/user",
        component: () => import("@/views/User.vue"), // 确保路径正确
        redirect: "", // 默认重定向到用户列表
        children: [
          {
            path: "",
            name: "UserTable",
            component: () => import("@/components/UserTable.vue"),
          },
          {
            path: "analytics",
            name: "ReadingAnalytics",
            component: () => import("@/components/ReadingAnalytics.vue"),
          },
          {
            path: "log",
            name: "Log",
            component: () => import("@/components/Log.vue"),
          },
        ],
      },
    ],
  },
  {
    path: "/:pathMatch(.*)",
    name: "NotFound",
    component: () => import("@/views/404.vue"),
  },
];

// 创建路由器
const router = createRouter({
  history: createWebHistory(),
  routes,
});

// 导出路由
export default router;